package org.budo.mybatis.session.delegate;

import org.budo.support.lang.util.ReflectUtil;

/**
 * @author limingwei2
 */
public class SqlSessionDelegateUtil {
    private static final String STR_1 = "Could not find result map ";

    private static final String STR_2 = ".$ResultMap";

    public static Class<?> findEntityTypeFromNoResultMapError(Throwable e) {
        String error = "" + e;
        int a = error.indexOf(STR_1);
        int b = error.indexOf(STR_2);
        if (a > 0 && b > a) {
            String type = error.substring(a + STR_1.length(), b);
            if (ReflectUtil.hasClass(type)) {
                return ReflectUtil.classForName(type);
            }
        }

        return null;
    }
}